//
//  ViewController.m
//  14作业礼物说
//
//  Created by dllo on 16/8/2.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "Label1CollectionReusableView.h"
#import "Label2CollectionReusableView.h"
#import "Label3CollectionReusableView.h"
#import "Label4CollectionReusableView.h"
#import "ImageCollectionViewCell.h"
#import "LabelAndCollectionViewReusableView.h"

@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    
    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"攻略",@"单品"]];
    self.navigationItem.titleView = seg;
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    
    UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(10, 84, self.view.bounds.size.width - 20, 40)];
    field.text = @"快选一份七夕礼物，送给心爱的Ta吧";
    field.backgroundColor = [UIColor blackColor];
    field.alpha = 0.2;
    field.textAlignment = YES;
    field.textColor = [UIColor whiteColor];
    [self.view addSubview:field];
    
    
    
    
    UICollectionViewFlowLayout *layout1 = [[UICollectionViewFlowLayout alloc] init];
    UICollectionView *collectionView1 = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 140, self.view.bounds.size.width, 500) collectionViewLayout:layout1];
    CGFloat width = (self.view.bounds.size.width - 30) / 2;
    layout1.itemSize = CGSizeMake(width, width / 2);
    layout1.minimumInteritemSpacing = 10;
    layout1.minimumLineSpacing = 10;
    layout1.sectionInset = UIEdgeInsetsMake(15, 5, 5, 5);
    
    [collectionView1 registerClass:[ImageCollectionViewCell class] forCellWithReuseIdentifier:@"cell1"];
    collectionView1.delegate = self;
    collectionView1.dataSource = self;
    [self.view addSubview:collectionView1];
    
    layout1.headerReferenceSize = CGSizeMake(width, 40);
    layout1.sectionHeadersPinToVisibleBounds = YES;
    
    
//    UICollectionViewFlowLayout *layout2 = [[UICollectionViewFlowLayout alloc] init];
//    UICollectionView *collectionView2 = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 100, CGRectGetWidth(self.view.bounds), 100) collectionViewLayout:layout2];
//    
//    layout2.itemSize = CGSizeMake((self.view.bounds.size.width - 30) / 2, 50);
//    layout2.minimumLineSpacing = 10;
//    layout2.minimumInteritemSpacing = 10;
//    layout2.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    
//    [ registerClass:[ImageCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
//    collectionView2.delegate = self;
//    collectionView2.dataSource = self;
//    [self.view addSubview:collectionView2];
    
    
    
    
    [collectionView1 registerClass:[LabelAndCollectionViewReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reuse1"];
    
    [collectionView1 registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reuse2"];
    [collectionView1 registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reuse3"];
    [collectionView1 registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reuse4"];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    
    return 4;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        LabelAndCollectionViewReusableView *reuse1 = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reuse1" forIndexPath:indexPath];
    reuse1.backgroundColor = [UIColor blueColor];
    return reuse1;
    } else if (indexPath.section == 1){
        Label2CollectionReusableView *reuse2 = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reuse2" forIndexPath:indexPath];
        reuse2.backgroundColor = [UIColor whiteColor];
        return reuse2;
    }
     else if (indexPath.section == 2) {
//
        Label3CollectionReusableView *reuse3 = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reuse3" forIndexPath:indexPath];
         reuse3.backgroundColor = [UIColor orangeColor];
         return reuse3;
        
    } else {
        Label4CollectionReusableView *reuse4 = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reuse4" forIndexPath:indexPath];
        reuse4.backgroundColor = [UIColor redColor];
        return reuse4;
    }

    
    
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (section == 0) {
        return 8;
    }
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        ImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
        UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:self.view.bounds];
        imageView1.image = [UIImage imageNamed:@"1"];
        return cell;
//
    } else {
        ImageCollectionViewCell *cell1 = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
        UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:self.view.bounds];
        imageView1.image = [UIImage imageNamed:@"0"];
        return cell1;
    }
//    }
//    cell1.backgroundColor = [UIColImageCollectionViewCellor greenColor];
//    [cell1.contentView addSubview:imageView1];
//    } else if (indexPath.section == 1) {
//        UICollectionViewCell *cell2 = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell2" forIndexPath:indexPath];
//        cell2.backgroundColor = [UIColor grayColor];
//        return cell2;
//    } else if (indexPath.section == 2) {
//        
//    } else {
//        
//    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
